import MsgConfig from '../msg-config/msg-config.vue'
import MsgConfirm from '../msg-confirm/msg-confirm.vue'
import { showMsg, msgList } from '../../../../vuex/action'

export default {
  name: 'msg-list',
  data() {
    return {
      mType1: {},
      mType2: {},
      mType3: {},
      showMsgConfig: false,
      showMsgConfirm: false,
      msgTitle: '配置消息提醒',
      news: {},
      send: {}
    }
  },
  components: {
    'vue-msg-config': MsgConfig,
    'vue-msg-confirm': MsgConfirm
  },
  vuex: {
    getters: {
      activityId: state => state.activityStoreId,
      activityName: state => state.activityStoreName,
      fresh: state => state.customMsgListNeedFresh
    },
    actions: {
      xMsgList: msgList,
      xShowMsg: showMsg
    }
  },
  methods: {
    getList() {
      var activityId = this.$route.params.id || this.activityId
      this.xMsgList({
        id: +activityId
      })
        .then((data) => {
          this.mType1 = data.type1
          this.mType2 = data.type2
          this.mType3 = data.type3
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    updateMsgWarn(warn) {
      this.showMsgConfig = true
      var activityId = this.$route.params.id || this.activityId
      this.news = {
        id: +activityId,
        type: +warn.type,
        msg: warn.msg,
        url: warn.url
      }
      switch (+warn.type) {
        case 1:
          this.news.typeContent = '活动上线信息提醒'
          break
        case 2:
          this.news.typeContent = '活动进行时消息提醒'
          break
        case 3:
          this.news.typeContent = '紧迫提醒'
          break
        default:
      }
    },
    sendMsg(type) {
      this.showMsgConfirm = true
      this.send = {
        id: +this.activityId,
        type: +type
      }
    }
  },
  ready() {
    this.getList({})
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
